interface NetImage {
    display(): void;
}

class RealImage implements NetImage {
    private fileName: string;
    public constructor(fileName: string) {
        this.fileName = fileName;
        this.loadFromDatabase(fileName);
    }
    public display(): void {
        console.log(`Displaying ${this.fileName} from database`);
    }
    private loadFromDatabase(fileName: string): void {
        console.log(`Loading ${fileName} from database`);
    }
}

class ProxyImage implements NetImage {
    private realImage: RealImage | null = null;
    private fileName: string;
    public constructor(fileName: string) {
        this.fileName = fileName;
    }
    public display(): void {
        if (this.realImage === null) {
            this.realImage = new RealImage(this.fileName);
        }
        this.realImage.display();
    }
}

function main() {
    const image: NetImage = new ProxyImage("test.jpg");
    image.display();
    image.display();
}

main();
